function res = question8(fid)
% QUETION8 - 
%   

    fprintf(fid,'\n\nP108第八题:\n');
    Precise = sqrt(pi)*exp(-1/4);
    
    H = [0.1,0.01,0.001];
    A = [-1,-10,-100];
    B = -A;
    for i = 1:3
        for j=1:3
            n = (B(j)-A(j))/H(i);
            mid(i,j)=multimid(@f,A(j),B(j),n);
        end
    end
    
    midres=Precise-mid;
    fprintf(fid,'复合中点不同截断和h的误差：\n');
    fprintf(fid,'%4.8e & %4.8e & %4.8e\n',midres);

    for i = 1:3
        adpt(i)=adp(@f,A(i),B(i),1e-12);
    end
    adpres = Precise - adpt;
    fprintf(fid,'自适应积分法不同截断的误差：\n');
    fprintf(fid,'%4.8e & ',adpres);
    i = 1;
    N = [8,16,32,64];
    for n =N
        gauss(i) = gausshermi(@cos,n);i=i+1;
    end
    gaussres= Precise-gauss;
    fprintf(fid,'\ngauss-hermite积分法不同n的误差：\n')
    fprintf(fid,'%d & ',N);
    fprintf(fid,'\n');
    fprintf(fid,'%4.8e & ',gaussres);
    
end

function y=f(x)
    sx = size(x);
    for i = 1:sx(1)
        for j = 1:sx(2)
            y(i,j) = exp(-x(i,j)^2)*cos(x(i,j));
        end
    end
end
